package cn.edu.scau.cmi.wujiaxian.client;

import java.io.IOException;

import org.springframework.context.ApplicationContext;

import cn.edu.scau.cmi.wujiaxian.spring.domain.Student;
import cn.edu.scau.cmi.wujiaxian.spring.domain.Teacher;
import cn.edu.scau.cmi.wujiaxian.spring.util.ApplicationContextUtil;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class SpringGraduationClient extends Application {

	private ApplicationContext applicationContext = ApplicationContextUtil.getApplicationContext();
	/**
	 * 开始方法
	 */
   @Override
   public void start(Stage primaryStage) {
	   VBox root = new VBox(10);
	   singleton(root, applicationContext);
       Scene scene = new Scene(root, 200, 100);
       primaryStage.setTitle("Spring毕业答辩实验");
       primaryStage.setScene(scene);
       primaryStage.show();
   }

   public Student getStudent(String name) {
	   return (Student) applicationContext.getBean("zhangsan");
   }
   
   /**
    * 单例模式的实验
    * @param pane
    */
   public void singleton(Pane pane, ApplicationContext applicationContext) {
	   Teacher teacher = (Teacher) applicationContext.getBean("liangzaoqing");
	   Student student = getStudent("zhangsan");

	   pane.getChildren().add(new Text("老师名字" + teacher.getName()));

       pane.getChildren().add(new Text("学生名字" + student.getName()));

   }
   
   public static void main(String[] args) {
//       launch(args);
       Platform.runLater(new Runnable() {
			public void run() {
				new SpringGraduationClient().start(new Stage());
			}
		});
   }
}